<template>
	<view class="print-task">
		<view>
			<u-cell-group>
				<u-cell title="选择打印机">
					<view slot="title">
						<u-row>
							<u-col span="5" class="text-right">
								<view>选择打印机：</view>
							</u-col>
							<u-col span="6">
								<view @click="printShowEv" class="print">{{printData.print}}</view>
							</u-col>
						</u-row>
					</view>
				</u-cell>
				<u-cell title="打印份数">
					<view slot="title" class="itm">
						<u-row>
							<u-col span="5" class="text-right">
								<view >打印份数：</view>
							</u-col>
							<u-col span="6">
								<view><u-number-box button-size="25" v-model="printData.qty"></u-number-box></view>
							</u-col>
						</u-row>
					</view>
				</u-cell>
			</u-cell-group>

			<!-- 			
			<view @click="printShow = true">
				选择打印机
			</view>
			<view>{{printData.print}}</view> -->
		</view>
		<!-- <view >
			<view>打印分数</view>
			<view><u-number-box v-model="printData.qty"></u-number-box></view>
		</view> -->
		<u-picker @cancel="printShow=false" @confirm="printEv" :show="printShow" :columns="columns"></u-picker>
	</view>
</template>

<script>
	import {
		ApibasicPrintFacilityListGet
	} from '@/common/api/basic.js';
	export default {
		name: "printTask",
		props: ["print_type"],
		data() {
			return {
				printShow: false,
				columns: [
					uni.getStorageSync('printfacility')
				],
				printData: {
					qty: 1,
					print: ''
				}
			}
		},
		onLoad() {
			
		},
		mounted() {
			console.log(this.print_type)
			this.printTypeEv()
			// this.searchGetEv()
		},
		methods: {
			printEv(val) {
				// this.printData.print = val.value[0]
				this.printTypeEv(val.value[0])
				this.printShow = false
			},
			printShowEv() {
				if (this.columns[0].length==0) {
					uni.showToast({
						title: '没有打印设备',
						icon :'none',
						duration: 2000
					});
					return
				}
				this.printShow = true
			},
			// 查询数据
			async searchGetEv() {
				try {
					uni.showLoading({
						title: '加载中',
						mask: true
					});
					let arr_data = await ApibasicPrintFacilityListGet()
					uni.hideLoading();
					if (arr_data.statusCode == 202) {
			
						uni.showModal({
							content: arr_data.data.msg,
							showCancel: false
						});
			
						return
					}

					if (arr_data.statusCode !== 200) {
						uni.showModal({
							content: '打印机查询失败',
							showCancel: false
						});
			
						return
					}
					console.log(arr_data.data)
					this.columns = [arr_data.data.result]
				} catch (err) {
					//TODO handle the exception
					console.log(err)
					uni.hideLoading();
					let message = '打印机查询接口请求失败请联系管理员'
					if (err.statusCode == 401) {
						message = err.data.msg
					}
					uni.showModal({
						content: message,
						showCancel: false
					});
				}
			},
			printTypeEv(val) {
				// print_type:sc 表示生产 cw表示财务打印
				if (val) {
					if (this.print_type == 'sc') {
						uni.setStorageSync('sc_print_type', val);
					} else if(this.print_type == 'cw') {
						uni.setStorageSync('cw_print_type', val);
					} else {
						uni.setStorageSync('sc_print_type', val);
					}
					this.printData.print = val
				} else {
					console.log('5555')
					console.log(this.print_type)
					if (this.print_type == 'sc') {
						this.printData.print = uni.getStorageSync('sc_print_type')
					} else if(this.print_type == 'cw') {
						this.printData.print = uni.getStorageSync('cw_print_type')
					} else {
						this.printData.print = uni.getStorageSync('sc_print_type')
					}
				}
				
			}
		}


	}
</script>
<!-- flex布局 -->
<!-- http://eyunzhu.com/cdata/U7hPT5w9uayLSIQ7qfFNUg -->
<style lang="scss">
	/deep/ .u-cell__title {
		text-align: left;
		height: 50rpx;
		line-height: 50rpx;
		font-size: 25rpx;
	}

	.print {
		// background-color: red;
		border-bottom: solid #E5E5E5 1px;
		width: 100%;
		display: block;
		height: 50rpx !important;
	}

	/deep/ .text-right {
		text-align: right !important;
		font-size: 30rpx !important;
	}
	/deep/ .uni-mask {
		z-index: 1200 !important; 
	}
</style>